<?php
  session_start();
?>

<!DOCTYPE html>
<html lang="en">        
<head>
        <title>CoBAGSys - Home</title>
        <link type="text/css" rel="stylesheet" href="css/mystyle.css">
	<script type="text/JavaScript" src="js/validate.js"></script>
	<script type>
		function ValidateFields() {
                	return ValidateFieldNotEmpty("resetPassForm", "email", "Email")
				&& ValidateFieldNotEmpty("resetPassForm","securityAnswer","Security Answer");			
		}
	</script>
</head>
<body>
    <?php
      require 'menus.php';
    ?>
    <?
    function getUserPassword($email,$securityAnswer)
	{
		$db = new Connect();

		$sql = "SELECT g.password from Guest g INNER JOIN MemberInfo mi USING(email) WHERE mi.email= '" . $email . "' AND mi.securityAnswer='"  . $securityAnswer . "'";
		//
		
		$result = $db->query($sql);
		
		if(!$result || mysql_num_rows($result) ==0)
		{
			return "";
		}
		else
		{
			$rows = $db->to_array($result);
			return $rows[0]['password'];
		}
	}
	
	function displayRows()
	{
			//foreach($rows)
	}
	
	
    ?>
    <div id="main">
	  <?php
		if(isset($_POST['getUserPassword']))
	        {
        	        $pw = getUserPassword($_POST['email'],$_POST['securityAnswer']);
			if($pw == "")
			{
				echo "You did not provide the correct email/security answer";
			}
			else
			{
        			echo "Your password is <b>" . $pw . "</b>";
			}
		}
	  ?> 
          <form id="resetPassForm" action="" onsubmit="return ValidateFields();" method="post">
		<fieldset>
			<legend>Identify yourself:</legend>
		<input type="text" name="email" placeholder="Username(email)"><br/>
		Security Question:
		<select name="securityQuestion">
			<option value="Why?" selected>Why?</option>
			<option value="a">a</option>
			<option value="What is love?">What is love?</option>
			<option value="Who?">Who?</option>
		</select></br>
		<input type="text" name="securityAnswer" placeholder="Security Answer">
		<p></p>
		<input type="submit" class="smallButton" name="getUserPassword" value="   Submit  "/>
		
		</fieldset> 
	 </form>	
	
    </div>
</body>  
</html>
        